import { BrowserRouter, Routes, Route } from "react-router-dom";
import Layout from "./pages/Layout";
import Home from "./pages/Home";
import Register from "./pages/Auth/register";
import Login from "./pages/Auth/login";
import { useContext } from "react";
import { AppContext } from "./Context/AppContext";
import Create from "./pages/Posts/create";
import Show from "./pages/Posts/show";
import Edit from "./pages/Posts/edit";

export default function Router() {
  const { user } = useContext(AppContext);
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Layout />}>
          <Route index element={<Home />} />
          <Route path="/create" element={<Create />} />
          <Route path="/posts/:id" element={<Show />} />
          <Route path="/posts/:id/edit" element={<Edit />} />
          <Route path="/register" element={user ? <Home /> : <Register />} />
          <Route path="/login" element={user ? <Home /> : <Login />} />
          {/* {user ? (
            <Route path="/login" element={<Login />} />
          ) : (
            <Route path="/register" element={<Register />} />
          )} */}
        </Route>
      </Routes>
    </BrowserRouter>
  );
}
